<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!--表格样式-->
    <style>
        .el-table .warning-row {
            background: oldlace;
        }

        .el-table .success-row {
            background: #f0f9eb;
        }
    </style>
</head>
<body>
<div id="app">
    <!--搜索表单：行内表单-->
    <el-form :inline="true" :model="brand" class="demo-form-inline">
        <el-form-item label="当前状态">
            <el-select v-model="brand.status" placeholder="当前状态">
                <el-option label="启用" value="1" align="center"></el-option>
                <el-option label="禁用" value="0" align="center"></el-option>
            </el-select>
        </el-form-item>

        <el-form-item label="企业名称">
            <el-input v-model="brand.companyName" placeholder="企业名称"></el-input>
        </el-form-item>

        <el-form-item label="品牌名称">
            <el-input v-model="brand.brandName" placeholder="品牌名称"></el-input>
        </el-form-item>

        <el-form-item>
            <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
    </el-form>

    <!--批量删除和新增按钮：朴素按钮-->
    <el-row>
        <el-button type="danger" plain>批量删除</el-button>
        <el-button type="primary" plain @click="dialogVisible=true">添加品牌</el-button>
    </el-row>

    <!--添加数据对话框：基本对话框-->
    <el-dialog
            title="添加品牌"
            :visible.sync="dialogVisible"
            width="30%">
        <!--添加品牌表单：典型表单
                怎么设置必须填写的*？-->
        <el-form ref="addForm" :model="addBrand" label-width="80px">
            <el-form-item label="品牌名称">
                <el-input v-model="addBrand.brandName"></el-input>
            </el-form-item>

            <el-form-item label="企业名称">
                <el-input v-model="addBrand.companyName"></el-input>
            </el-form-item>

            <el-form-item label="排序">
                <el-input v-model="addBrand.ordered"></el-input>
            </el-form-item>

            <el-form-item label="备注">
                <el-input type="textarea" v-model="addBrand.description"></el-input>
            </el-form-item>

            <el-form-item label="状态">
                <el-switch
                        v-model="addBrand.status"
                        active-color="#13ce66"
                        active-value="1"
                        inactive-value="0">
                </el-switch>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="addSubmit">提交</el-button>
                <el-button @click="dialogVisible=false">取消</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>

    <!--数据表格：带状态的表格-->
    <template>
        <el-table
                :data="tableData"
                style="width: 100%"
                :row-class-name="tableRowClassName"
                @selection-change="handleSelectionChange">
            <!--复选框-->
            <el-table-column
                    type="selection"
                    width="55">
            </el-table-column>
            <!--序号-->
            <el-table-column
                    label="序号"
                    type="index"
                    width="50"
                    align="center">
            </el-table-column>
            <!--表头-->
            <el-table-column
                    prop="brandName"
                    label="品牌名称"
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="companyName"
                    label="企业名称"
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="ordered"
                    label="排序"
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="status"
                    label="当前状态"
                    align="center">
            </el-table-column>
            <el-table-column
                    label="操作"
                    align="center">
                <el-button type="primary">修改</el-button>
                <el-button type="danger">删除</el-button>
            </el-table-column>
        </el-table>
    </template>

    <!--分页工具条：完整分页功能-->
    <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[5, 10, 15, 20]"
            :page-size="5"
            layout="total, sizes, prev, pager, next, jumper"
            :total="100">
    </el-pagination>
</div>

<script src="../js/vue.js"></script>
<script src="../element-ui/lib/index.js"></script>
<link rel="stylesheet" href="../element-ui/lib/theme-chalk/index.css">
<script>
    new Vue({
        el: "#app",
        data() {
            return {
                //表格数据模型
                tableData: [{
                    brandID:'1',
                    brandName: '华为',
                    companyName: '华为科技有限公司',
                    ordered: '100',
                    description: '华为致力于把数字世界带入每个人、每个家庭、每个组织，构建万物互联的智能世界',
                    status: "1"
                }, {
                    brandID:'2',
                    brandName: '小米',
                    companyName: '小米科技',
                    ordered: '200',
                    description: 'are you ok',
                    status: "0"
                }, {
                    brandID:'3',
                    brandName: '百度',
                    companyName: '百度控股有限公司',
                    ordered: '150',
                    description: '世界很复杂，百度更懂你',
                    status: "1"
                }, {
                    brandID:'4',
                    brandName: '三只松鼠',
                    companyName: '三只松鼠股份有限公司',
                    ordered: '100',
                    description: '好吃不上火',
                    status: "1"
                }, {
                    brandID:'5',
                    brandName: '小官精品沐足',
                    companyName: '小官养生保健集团',
                    ordered: '250',
                    description: '沐足就选精品，保健就选小官',
                    status: "0"
                }],
                //复选框数据模型
                multipleSelection: [],
                //查询数据模型
                brand: {
                    brandID:'',
                    brandName: '',
                    companyName: '',
                    ordered: '',
                    description: '',
                    status: '0'
                },
                //添加按钮对话框数据模型
                dialogVisible: false,
                //添加品牌表单数据模型
                addBrand: {
                    brandID:'',
                    brandName: '',
                    companyName: '',
                    ordered: '',
                    description: '',
                    status: '0'
                },
                //分页工具条数据模型
                currentPage: 100
            }
        },
        methods: {
            //带状态的表格
            tableRowClassName({row, rowIndex}) {
                if (rowIndex === 1) {
                    return 'warning-row';
                } else if (rowIndex === 3) {
                    return 'success-row';
                }
                return '';
            },
            //复选框选中绑定事件
            handleSelectionChange(val) {
                this.multipleSelection = val;
                console.log(val);
            },
            //查询按钮绑定事件
            onSubmit() {
                console.log(this.brand);
            },
            //添加按钮对话框绑定事件
            handleClose(done) {
                this.$confirm('确认关闭？')
                    .then(_ => {
                        done();
                    })
                    .catch(_ => {});
            },
            //添加品牌表单绑定事件
            addSubmit() {
                console.log(this.addBrand);
            },
            //分页工具条绑定事件
            handleSizeChange(val) {
                console.log(`每页 ${val} 条`);
            },
            handleCurrentChange(val) {
                console.log(`当前页: ${val}`);
            }
        }
    })
</script>
</body>
</html>